/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroFornecedor.java
 *
 * Created on 05/04/2011, 01:43:15
 */
package Tela;

import Classe.BD;
import Classe.Bairro;
import Classe.Cidade;
import Classe.Endereco;
import Classe.Estado;
import Classe.Fornecedor;
import Classe.Validacao;
import java.awt.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane; 

/**
 *
 * @author gladson
 */
public class CadastroFornecedor extends Validacao {

    private Component frameI;

    /** Creates new form CadastroFornecedor */
    public CadastroFornecedor() {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        iniciar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jpnCadastroFornecedor = new javax.swing.JPanel();
        pnlEmpresaFornecedor = new javax.swing.JPanel();
        lblRazaoSocialFornecedor = new javax.swing.JLabel();
        txtRazaoSocialFornecedor = new javax.swing.JTextField();
        lblNomeFantasiaFornecedor = new javax.swing.JLabel();
        txtNomeFantasiaFornecedor = new javax.swing.JTextField();
        lblCnpjFornecedor = new javax.swing.JLabel();
        lblInscricaoEstadualFornecedor = new javax.swing.JLabel();
        stxtInscricaoEstadualFornecedor = new javax.swing.JTextField();
        sTxtCnpjFornecedor = new javax.swing.JFormattedTextField();
        lblSituacao = new javax.swing.JLabel();
        cbSituacaoFornecedor = new javax.swing.JComboBox();
        sTxtDataFornecedor = new javax.swing.JTextField();
        lblDataFornecedor = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        cbBairroFornecedor = new javax.swing.JComboBox();
        jLabel150 = new javax.swing.JLabel();
        cbEnderecoFornecedor = new javax.swing.JComboBox();
        jLabel151 = new javax.swing.JLabel();
        jLabel148 = new javax.swing.JLabel();
        cbCidadeFornecedor = new javax.swing.JComboBox();
        jLabel149 = new javax.swing.JLabel();
        ItxtNumFonecedor = new javax.swing.JTextField();
        jLabel147 = new javax.swing.JLabel();
        jLabel152 = new javax.swing.JLabel();
        cbEstadoFornecedor = new javax.swing.JComboBox();
        jLabel146 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        StxtSalaFornecedor = new javax.swing.JTextField();
        stxtCepFornecedor = new javax.swing.JFormattedTextField();
        cbComplFornecedor = new javax.swing.JComboBox();
        btSalvarFornecedor = new javax.swing.JButton();
        btLimparFornecedor = new javax.swing.JButton();
        btSairFornecedor = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        stxtObsFornecedor = new javax.swing.JTextArea();
        pnlContatoPessoaJuridica = new javax.swing.JPanel();
        lblNomePessoaJuridica = new javax.swing.JLabel();
        sTxtNomeFornecedor = new javax.swing.JTextField();
        lblTelefonePessoaJuridica = new javax.swing.JLabel();
        sLblTelefoneFornecedor = new javax.swing.JFormattedTextField();
        lblFaxPessoaJuridica = new javax.swing.JLabel();
        stxtFaxFornecedor = new javax.swing.JFormattedTextField();
        lblEmailPessoaJuridica = new javax.swing.JLabel();
        stxtEmailFornecedor = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jpnCadastroFornecedor.setBackground(new java.awt.Color(255, 255, 255));
        jpnCadastroFornecedor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Cadastro Fornecedor ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N
        jpnCadastroFornecedor.setPreferredSize(new java.awt.Dimension(800, 600));

        pnlEmpresaFornecedor.setBackground(new java.awt.Color(255, 255, 255));
        pnlEmpresaFornecedor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Empresa", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        lblRazaoSocialFornecedor.setFont(new java.awt.Font("Arial", 1, 11));
        lblRazaoSocialFornecedor.setText("Razão Social");

        txtRazaoSocialFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblNomeFantasiaFornecedor.setFont(new java.awt.Font("Arial", 1, 11));
        lblNomeFantasiaFornecedor.setText("Nome Fantasia");

        txtNomeFantasiaFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblCnpjFornecedor.setFont(new java.awt.Font("Arial", 1, 11));
        lblCnpjFornecedor.setText("CNPJ");

        lblInscricaoEstadualFornecedor.setFont(new java.awt.Font("Arial", 1, 11));
        lblInscricaoEstadualFornecedor.setText("Inscição Estadual");

        stxtInscricaoEstadualFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        sTxtCnpjFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            sTxtCnpjFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lblSituacao.setFont(new java.awt.Font("Arial", 1, 11));
        lblSituacao.setText("Situação");

        cbSituacaoFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { null, "ATIVO", "INATIVO" }));
        cbSituacaoFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout pnlEmpresaFornecedorLayout = new javax.swing.GroupLayout(pnlEmpresaFornecedor);
        pnlEmpresaFornecedor.setLayout(pnlEmpresaFornecedorLayout);
        pnlEmpresaFornecedorLayout.setHorizontalGroup(
            pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtRazaoSocialFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                    .addComponent(lblRazaoSocialFornecedor)
                    .addComponent(lblNomeFantasiaFornecedor)
                    .addComponent(txtNomeFantasiaFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                    .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                        .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sTxtCnpjFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblCnpjFornecedor))
                        .addGap(18, 18, 18)
                        .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(stxtInscricaoEstadualFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(lblInscricaoEstadualFornecedor)))
                        .addGap(18, 18, 18)
                        .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                                .addComponent(lblSituacao)
                                .addGap(15, 15, 15))
                            .addComponent(cbSituacaoFornecedor, 0, 423, Short.MAX_VALUE))))
                .addContainerGap())
        );
        pnlEmpresaFornecedorLayout.setVerticalGroup(
            pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                .addComponent(lblRazaoSocialFornecedor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRazaoSocialFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNomeFantasiaFornecedor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNomeFantasiaFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlEmpresaFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                            .addComponent(lblCnpjFornecedor)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(sTxtCnpjFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                            .addComponent(lblInscricaoEstadualFornecedor)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(stxtInscricaoEstadualFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlEmpresaFornecedorLayout.createSequentialGroup()
                        .addComponent(lblSituacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbSituacaoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        sTxtDataFornecedor.setFont(new java.awt.Font("Arial", 0, 12));
        sTxtDataFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        Date data = new Date(System.currentTimeMillis());
        SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/yyyy");/*
        */
        sTxtDataFornecedor.setText(formatarDate.format(data));
        sTxtDataFornecedor.setEnabled(false);
        sTxtDataFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sTxtDataFornecedorActionPerformed(evt);
            }
        });

        lblDataFornecedor.setFont(new java.awt.Font("Arial", 1, 12));
        lblDataFornecedor.setText("Data");

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        cbBairroFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        cbBairroFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbBairroFornecedor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbBairroFornecedorItemStateChanged(evt);
            }
        });

        jLabel150.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel150.setText("Rua/Av.");

        cbEnderecoFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        cbEnderecoFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbEnderecoFornecedor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbEnderecoFornecedorItemStateChanged(evt);
            }
        });

        jLabel151.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel151.setText("Nº.");

        jLabel148.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel148.setText("Cidade");

        cbCidadeFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        cbCidadeFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbCidadeFornecedor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbCidadeFornecedorItemStateChanged(evt);
            }
        });

        jLabel149.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel149.setText("Bairro");

        ItxtNumFonecedor.setFont(new java.awt.Font("Arial", 0, 12));
        ItxtNumFonecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel147.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel147.setText("Estado");

        jLabel152.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel152.setText("Complemento");

        cbEstadoFornecedor.setFont(new java.awt.Font("Arial", 0, 12));
        cbEstadoFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        cbEstadoFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbEstadoFornecedor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbEstadoFornecedorItemStateChanged(evt);
            }
        });

        jLabel146.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel146.setText("CEP");

        jLabel7.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel7.setText("Sala");

        StxtSalaFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        try {
            stxtCepFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        cbComplFornecedor.setModel(new javax.swing.DefaultComboBoxModel(new String[] {null, "SALA", "LOJA", "GALPAO"}));
        cbComplFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbEstadoFornecedor, 0, 92, Short.MAX_VALUE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel147)
                                .addGap(48, 48, 48)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel148)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(cbCidadeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel149)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel151)
                                        .addComponent(ItxtNumFonecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(27, 27, 27)
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel152)
                                        .addComponent(cbComplFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addComponent(cbBairroFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE))
                    .addComponent(jLabel150)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(cbEnderecoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(stxtCepFornecedor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel146)
                            .addGap(61, 61, 61)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(StxtSalaFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                            .addComponent(jLabel7))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(stxtCepFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel146)
                        .addGap(27, 27, 27))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel147)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbEstadoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel148)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbCidadeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel149)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbBairroFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel150)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cbEnderecoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel151)
                                .addComponent(jLabel152))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ItxtNumFonecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cbComplFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel7)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGap(19, 19, 19)
                            .addComponent(StxtSalaFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btSalvarFornecedor.setText("Salvar");
        btSalvarFornecedor.setToolTipText("Salvar");
        btSalvarFornecedor.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSalvarFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarFornecedorActionPerformed(evt);
            }
        });

        btLimparFornecedor.setText("Limpar");
        btLimparFornecedor.setToolTipText("Limpar");
        btLimparFornecedor.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btLimparFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparFornecedorActionPerformed(evt);
            }
        });

        btSairFornecedor.setText("Sair");
        btSairFornecedor.setToolTipText("Sair");
        btSairFornecedor.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSairFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btSairFornecedorMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btSairFornecedorMouseReleased(evt);
            }
        });
        btSairFornecedor.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                btSairFornecedorMouseMoved(evt);
            }
        });
        btSairFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairFornecedorActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Observação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        stxtObsFornecedor.setColumns(20);
        stxtObsFornecedor.setLineWrap(true);
        stxtObsFornecedor.setRows(5);
        stxtObsFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jScrollPane2.setViewportView(stxtObsFornecedor);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlContatoPessoaJuridica.setBackground(new java.awt.Color(255, 255, 255));
        pnlContatoPessoaJuridica.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Contato", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        lblNomePessoaJuridica.setFont(new java.awt.Font("Arial", 1, 11));
        lblNomePessoaJuridica.setText("Nome");

        sTxtNomeFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblTelefonePessoaJuridica.setFont(new java.awt.Font("Arial", 1, 11));
        lblTelefonePessoaJuridica.setText("Telefone");

        sLblTelefoneFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            sLblTelefoneFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lblFaxPessoaJuridica.setFont(new java.awt.Font("Arial", 1, 11));
        lblFaxPessoaJuridica.setText("Fax");

        stxtFaxFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            stxtFaxFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lblEmailPessoaJuridica.setFont(new java.awt.Font("Arial", 1, 11));
        lblEmailPessoaJuridica.setText("E-mail");

        stxtEmailFornecedor.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout pnlContatoPessoaJuridicaLayout = new javax.swing.GroupLayout(pnlContatoPessoaJuridica);
        pnlContatoPessoaJuridica.setLayout(pnlContatoPessoaJuridicaLayout);
        pnlContatoPessoaJuridicaLayout.setHorizontalGroup(
            pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlContatoPessoaJuridicaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(stxtEmailFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
                    .addGroup(pnlContatoPessoaJuridicaLayout.createSequentialGroup()
                        .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNomePessoaJuridica)
                            .addComponent(sTxtNomeFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sLblTelefoneFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblTelefonePessoaJuridica))
                        .addGap(18, 18, 18)
                        .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblFaxPessoaJuridica)
                            .addComponent(stxtFaxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(lblEmailPessoaJuridica))
                .addContainerGap())
        );

        pnlContatoPessoaJuridicaLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {sLblTelefoneFornecedor, stxtFaxFornecedor});

        pnlContatoPessoaJuridicaLayout.setVerticalGroup(
            pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlContatoPessoaJuridicaLayout.createSequentialGroup()
                .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlContatoPessoaJuridicaLayout.createSequentialGroup()
                        .addComponent(lblNomePessoaJuridica)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sTxtNomeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlContatoPessoaJuridicaLayout.createSequentialGroup()
                        .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblFaxPessoaJuridica)
                            .addComponent(lblTelefonePessoaJuridica))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlContatoPessoaJuridicaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sLblTelefoneFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(stxtFaxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblEmailPessoaJuridica)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stxtEmailFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jpnCadastroFornecedorLayout = new javax.swing.GroupLayout(jpnCadastroFornecedor);
        jpnCadastroFornecedor.setLayout(jpnCadastroFornecedorLayout);
        jpnCadastroFornecedorLayout.setHorizontalGroup(
            jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnCadastroFornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnCadastroFornecedorLayout.createSequentialGroup()
                        .addGroup(jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pnlContatoPessoaJuridica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jpnCadastroFornecedorLayout.createSequentialGroup()
                                .addComponent(btSalvarFornecedor)
                                .addGap(18, 18, 18)
                                .addComponent(btLimparFornecedor)
                                .addGap(18, 18, 18)
                                .addComponent(btSairFornecedor)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnCadastroFornecedorLayout.createSequentialGroup()
                        .addComponent(lblDataFornecedor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sTxtDataFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(pnlEmpresaFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jpnCadastroFornecedorLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btLimparFornecedor, btSairFornecedor, btSalvarFornecedor});

        jpnCadastroFornecedorLayout.setVerticalGroup(
            jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnCadastroFornecedorLayout.createSequentialGroup()
                .addGroup(jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDataFornecedor)
                    .addComponent(sTxtDataFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlEmpresaFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addGroup(jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnCadastroFornecedorLayout.createSequentialGroup()
                        .addComponent(pnlContatoPessoaJuridica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpnCadastroFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btSalvarFornecedor)
                            .addComponent(btLimparFornecedor)
                            .addComponent(btSairFornecedor)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(42, Short.MAX_VALUE))
        );

        jpnCadastroFornecedorLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btLimparFornecedor, btSairFornecedor, btSalvarFornecedor});

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpnCadastroFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jpnCadastroFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-808)/2, (screenSize.height-627)/2, 808, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void sTxtDataFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sTxtDataFornecedorActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_sTxtDataFornecedorActionPerformed

    private void btSalvarFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarFornecedorActionPerformed
        if (validar()) {

            Fornecedor forn = new Fornecedor();

            //------------- PEGANDO A DATA ATUAL E FORMATANDO ----------------------------------------------
            Date data = new Date(System.currentTimeMillis());
            SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/yy");
            // --------------FIM DE PEGAR E FORMATAR A DATA ------------------------------------------------

            forn.setData_cadas_fornecedor(formatarDate.format(data));
            forn.setRazaoSocialFornecedor(txtRazaoSocialFornecedor.getText().trim().toUpperCase());
            forn.setNomeFantasiaFornecedor(txtNomeFantasiaFornecedor.getText().trim().toUpperCase());
            forn.setCnpjFornecedor(sTxtCnpjFornecedor.getText().trim().toUpperCase());
            forn.setInscEstadualFornecedor(stxtInscricaoEstadualFornecedor.getText().trim().toUpperCase());
            forn.setTelFornecedor(sLblTelefoneFornecedor.getText().trim().toUpperCase());
            forn.setFaxFornecedor(stxtFaxFornecedor.getText().trim().toUpperCase());
            forn.setEmailFornecedor(stxtEmailFornecedor.getText().trim().toUpperCase());
            forn.setContatoFornecedor(sTxtNomeFornecedor.getText().trim().toUpperCase());
            forn.setNumFornecedor(Integer.parseInt(ItxtNumFonecedor.getText().trim()));
            forn.setSalaFornecedor(StxtSalaFornecedor.getText().trim().toUpperCase());
            forn.setSituacaoFornecedor((String) cbSituacaoFornecedor.getSelectedItem());

            Endereco itemEnd = (Endereco) cbEnderecoFornecedor.getSelectedItem();

            forn.setObsFornecedor(stxtObsFornecedor.getText().trim().toUpperCase());
            forn.setComplementoFornecedor((String) cbComplFornecedor.getSelectedItem());

            String sql = "INSERT INTO FORNECEDOR (ID_FORNECEDOR,DATA_CADAS_FORNECEDOR,RAZAO_FORNECEDOR,NOME_FANT_FORNECEDOR,CNPJ_FORNECEDOR,INSC_EST_FORNECEDOR,TEL_FORNECEDOR,FAX_FORNECEDOR,EMAIL_FORNECEDOR,CONTATO_FORNECEDOR,NUM_FORNECEDOR,SALA_FORNECEDOR,SITUACAO_FORNECEDOR,ID_ENDERECO,OBS_FORNECEDOR,COMP_FORNECEDOR) values (SQ_FORNECEDOR.NEXTVAL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

            Object[] parametros = {forn.getData_cadas_fornecedor(), forn.getRazaoSocialFornecedor(), forn.getNomeFantasiaFornecedor(), forn.getCnpjFornecedor(), forn.getInscEstadualFornecedor(), forn.getTelFornecedor(), forn.getFaxFornecedor(), forn.getEmailFornecedor(), forn.getContatoFornecedor(), forn.getNumFornecedor(), forn.getSalaFornecedor(), forn.getSituacaoFornecedor(), itemEnd.getIdEndereco(), forn.getObsFornecedor(), forn.getComplementoFornecedor()};

            Object[] tipos = {String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, Integer.class, String.class, String.class, Integer.class, String.class, String.class};

            BD banco = new BD();

            try {
                banco.executar(sql, parametros, tipos);
                JOptionPane.showMessageDialog(frameI, "Cadastro salvo com Sucesso");
                this.dispose();
                CadastroFornecedor forme = new CadastroFornecedor();
                forme.setVisible(true);

            } catch (Exception ex) {
                Logger.getLogger(CadastroFornecedor.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

}//GEN-LAST:event_btSalvarFornecedorActionPerformed

    private void btSairFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSairFornecedorMouseClicked
        this.dispose();
        // TODO add your handling code here:
}//GEN-LAST:event_btSairFornecedorMouseClicked

    private void btSairFornecedorMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSairFornecedorMouseReleased
        // TODO add your handling code here:
}//GEN-LAST:event_btSairFornecedorMouseReleased

    private void btSairFornecedorMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSairFornecedorMouseMoved
        // TODO add your handling code here:
}//GEN-LAST:event_btSairFornecedorMouseMoved

    private void btSairFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairFornecedorActionPerformed
        this.dispose();
        //System.exit(0);
        // TODO add your handling code here:
}//GEN-LAST:event_btSairFornecedorActionPerformed

    private void cbEstadoFornecedorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbEstadoFornecedorItemStateChanged
        try {

            String sql;
            cbCidadeFornecedor.removeAllItems(); // limpa a caixa de cidades atual.

            if (cbEstadoFornecedor.getSelectedItem() != null) {
                Estado itemEst = (Estado) cbEstadoFornecedor.getSelectedItem();
                sql = "Select * from cidade where id_uf = '" + itemEst.getIdUf() + "' order by NOME_CIDADE";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Cidade cidade1 = new Cidade();
                cbCidadeFornecedor.addItem(cidade1);
                while (r.next()) {
                    Cidade cidade = new Cidade();

                    cidade.setIdCidade(r.getInt("id_cidade"));
                    String nomeCid = r.getString("NOME_CIDADE");
                    cidade.setNomeCidade(nomeCid);


                    cbCidadeFornecedor.addItem(cidade);
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }//GEN-LAST:event_cbEstadoFornecedorItemStateChanged

    private void cbCidadeFornecedorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbCidadeFornecedorItemStateChanged
        try {

            String sql;
            cbBairroFornecedor.removeAllItems(); // limpa a caixa de cidades atual.
            if (cbCidadeFornecedor.getSelectedItem() != null) {
                Cidade itemcid = (Cidade) cbCidadeFornecedor.getSelectedItem();

                sql = "Select * from bairro where id_cidade = " + itemcid.getIdCidade() + " order by NOME_BAIRRO";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Bairro bairro1 = new Bairro();
                cbBairroFornecedor.addItem(bairro1);
                while (r.next()) {

                    Bairro bairro = new Bairro();

                    bairro.setIdBairro(r.getInt("id_bairro"));
                    String nomeBair = r.getString("NOME_BAIRRO");
                    bairro.setNomeBairro(nomeBair);

                    cbBairroFornecedor.addItem(bairro);
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }//GEN-LAST:event_cbCidadeFornecedorItemStateChanged

    private void cbBairroFornecedorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbBairroFornecedorItemStateChanged
        try {

            String sql;
            cbEnderecoFornecedor.removeAllItems(); // limpa a caixa de cidades atual.
            if (cbBairroFornecedor.getSelectedItem() != null) {

                Bairro itemBai = (Bairro) cbBairroFornecedor.getSelectedItem();

                sql = "Select * from endereco where id_bairro = " + itemBai.getIdBairro() + "order by NOME_ENDERECO";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Endereco end1 = new Endereco();
                cbEnderecoFornecedor.addItem(end1);

                while (r.next()) {


                    Endereco end = new Endereco();

                    end.setIdEndereco(r.getInt("id_endereco"));

                    end.setNomeEndereco(r.getString("NOME_ENDERECO"));

                    end.setCepEndereco(r.getString("cep"));

                    cbEnderecoFornecedor.addItem(end);
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }//GEN-LAST:event_cbBairroFornecedorItemStateChanged

    private void cbEnderecoFornecedorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbEnderecoFornecedorItemStateChanged
        if (cbEnderecoFornecedor.getSelectedItem() != null) {
            Endereco itemEnd = (Endereco) cbEnderecoFornecedor.getSelectedItem();

            stxtCepFornecedor.setText(itemEnd.getCepEndereco());
            stxtCepFornecedor.setEnabled(false);
        }
    }//GEN-LAST:event_cbEnderecoFornecedorItemStateChanged

    private void btLimparFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparFornecedorActionPerformed
        this.dispose();
        CadastroFornecedor forme = new CadastroFornecedor();
        forme.setVisible(true);

    }//GEN-LAST:event_btLimparFornecedorActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroFornecedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ItxtNumFonecedor;
    private javax.swing.JTextField StxtSalaFornecedor;
    private javax.swing.JButton btLimparFornecedor;
    private javax.swing.JButton btSairFornecedor;
    private javax.swing.JButton btSalvarFornecedor;
    private javax.swing.JComboBox cbBairroFornecedor;
    private javax.swing.JComboBox cbCidadeFornecedor;
    private javax.swing.JComboBox cbComplFornecedor;
    private javax.swing.JComboBox cbEnderecoFornecedor;
    private javax.swing.JComboBox cbEstadoFornecedor;
    private javax.swing.JComboBox cbSituacaoFornecedor;
    private javax.swing.JLabel jLabel146;
    private javax.swing.JLabel jLabel147;
    private javax.swing.JLabel jLabel148;
    private javax.swing.JLabel jLabel149;
    private javax.swing.JLabel jLabel150;
    private javax.swing.JLabel jLabel151;
    private javax.swing.JLabel jLabel152;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel jpnCadastroFornecedor;
    private javax.swing.JLabel lblCnpjFornecedor;
    private javax.swing.JLabel lblDataFornecedor;
    private javax.swing.JLabel lblEmailPessoaJuridica;
    private javax.swing.JLabel lblFaxPessoaJuridica;
    private javax.swing.JLabel lblInscricaoEstadualFornecedor;
    private javax.swing.JLabel lblNomeFantasiaFornecedor;
    private javax.swing.JLabel lblNomePessoaJuridica;
    private javax.swing.JLabel lblRazaoSocialFornecedor;
    private javax.swing.JLabel lblSituacao;
    private javax.swing.JLabel lblTelefonePessoaJuridica;
    private javax.swing.JPanel pnlContatoPessoaJuridica;
    private javax.swing.JPanel pnlEmpresaFornecedor;
    private javax.swing.JFormattedTextField sLblTelefoneFornecedor;
    private javax.swing.JFormattedTextField sTxtCnpjFornecedor;
    private javax.swing.JTextField sTxtDataFornecedor;
    private javax.swing.JTextField sTxtNomeFornecedor;
    private javax.swing.JFormattedTextField stxtCepFornecedor;
    private javax.swing.JTextField stxtEmailFornecedor;
    private javax.swing.JFormattedTextField stxtFaxFornecedor;
    private javax.swing.JTextField stxtInscricaoEstadualFornecedor;
    private javax.swing.JTextArea stxtObsFornecedor;
    private javax.swing.JTextField txtNomeFantasiaFornecedor;
    private javax.swing.JTextField txtRazaoSocialFornecedor;
    // End of variables declaration//GEN-END:variables

    private void iniciar() {


        try {
            String sql = "Select * from estado order by id_uf";
            BD bd = new BD();
            ResultSet r1 = bd.consultar(sql);

            Estado est = new Estado();
            cbEstadoFornecedor.addItem(est);

            while (r1.next()) {
                Estado estado = new Estado();
                String sigla = r1.getString("id_uf");
                // preenchendo informacoes do objeto
                estado.setIdUf(sigla);

                cbEstadoFornecedor.addItem(estado);
            }



        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }

    public boolean validar() {
        boolean Resultado = true;
        //////////////////////////////////////////////////////////////////  

        if (validarRazaoENome(txtRazaoSocialFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarRazaoENome(txtNomeFantasiaFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarCnpj(sTxtCnpjFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarInscEst(stxtInscricaoEstadualFornecedor.getText()) == false) {
            Resultado = false;
        } else if (cbSituacaoFornecedor.getSelectedItem() == null) {
            Resultado = false;
            JOptionPane.showMessageDialog(frameI, "O preemchimento do campo Situação é obrigatório!");
        } else if (stxtCepFornecedor.getText().trim().equals(".   -")) {
            Resultado = false;
            JOptionPane.showMessageDialog(frameI, "O preemchimento do campo Endereço é obrigatório!");
        } else if (validarNumero(ItxtNumFonecedor.getText()) == false) {
            Resultado = false;
        } else if (cbComplFornecedor.getSelectedItem() == null) {
            Resultado = false;
            JOptionPane.showMessageDialog(frameI, "O preemchimento do campo Complemento é obrigatório");
        } else if (validarSalaApart(StxtSalaFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarNome(sTxtNomeFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarTelefone(sLblTelefoneFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarTelefone(stxtFaxFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarEmail(stxtEmailFornecedor.getText()) == false) {
            Resultado = false;
        } else if (validarObservacao(stxtObsFornecedor.getText()) == false) {
            Resultado = false;
        }


        return Resultado;
    }
}
